﻿{	
	var r = new RegExp("(^|(.*?\\/))(spcommon.js)(\\?|$)"),
	s = document.getElementsByTagName('script'),
	src, m, baseurl222 = "";
	for(var i=0, len=s.length; i<len; i++) {
		src = s[i].getAttribute('src');
		if(src) {
			var m = src.match(r);
			if(m) {
				baseurl222 = m[1];
				break;
			}
		}
	}
//    inputScript(baseurl222+'zTree/jquery.ztree.core-3.3.min.js');
//    inputCSS('zTree/zTreeStyle.css');
}
function inputScript(inc){
    var script='<'+'script type="text/javascript" src="'+inc+'"'+'><'+'/script>'; 
    document.writeln(script);
}
function inputCSS(style){
        var css='<'+'link rel="stylesheet" href="'+baseurl222+style+'"><'+'/>'; 
    document.writeln(css);
}


function alertx(msg)
{
    var str='<div id="id_select_kz_dialog_111" style="display:none;font-size: .5em;padding-top: .1em;background:transparent; padding-bottom: .1em;text-align:center"><p id="id_p_message" style="margin-top:20px;font-size:15px;">'+msg+'</p></div>';
    $("body").append(str);
    $("#id_select_kz_dialog_111" ).dialog({close:funclose,hide:{effect:'fade',mode:'hide'},show:{ effect: 'fade',direction:'up', duration:'250ms',times:2 ,percent:50},resizable:false,autoOpen: false,width:280,height:120,"取消":function(){$("#id_select_kz_dialog_111" ).dialog("close" );}});
    diaobj=$("#id_select_kz_dialog_111" ).dialog("open"); $("#id_select_kz_dialog_111" ).css("height","70px");
    $("#id_select_kz_dialog_111" ).parent().css("font-size",".6em");
    document.getElementById("id_select_kz_dialog_111" ).parentNode.style["position"]="absolute";
    document.getElementById("id_select_kz_dialog_111" ).parentNode.style["background"]="#f8fae9";//#f8fae9";
    document.getElementById("id_select_kz_dialog_111" ).parentNode.style["background-color"]="#f8fae9";//#f8fae9";
    document.getElementById("id_select_kz_dialog_111" ).parentNode.style["border"]="2px solid #A6C9E2";
    var hei=document.parentWindow.parent.document.documentElement.clientHeight;
    var wid=document.documentElement.clientWidth;
    $("#id_select_kz_dialog_111" ).parent().css("top",hei/2-60+document.documentElement.scrollTop);
    $("#id_select_kz_dialog_111" ).parent().css("left",wid/2-140);
    var time=0;
    function closedialog(){if(time==1){clearTimeout(interval);$("#id_select_kz_dialog_111" ).dialog("close" );}time++;}
    event.cancelBubble=true;
    $("body").bind("click",bodyclick);
    function bodyclick() { alertex("cc", true); $("#id_select_kz_dialog_111").dialog("close"); $("body").unbind("click", bodyclick); }
    function funclose(){$("#id_select_kz_dialog_111" ).remove();}
}
/*
   Function: GetFirstSmObject
   
   描述：获取第一个满足条件的对象
   
   参数:
   
      dbalias - 数据库在session中的别名
      
      tablename - 表名
      
      condition - 查询条件
      
      callback - 服务器成功返回结果后的回调函数
      
      async - 是否异步调用，true为异步，false为同步
      
   返回值:
   
      返回第一个满足条件的对象
*/
function GetFirstSmObject(dbalias,tablename,condition,succallback,async,faicallback)
{
    
	connectajax(DBCenterServiceUrl+"/Core.asmx/GetFirstSmObject",succallback==null?null:succallback,"{'dbalias':'"+dbalias+"','tablename':'" + tablename + "','condition':'"+condition+ "'}",async,faicallback==null?null:faicallback);
}


/*
   Function: InitMeta
   
   描述：根据传入的常量类型DM填充<select>标签，可以有多个，多个之间以逗号分割
   
   参数:
   
      selectids - <select> 元素的id，多个之间以逗号分割
        
      consttypes - 常量类型的代码，例如KCK_JJLX
      
   返回值:
   
       无
*/
function InitMeta(selectids,consttypes,async)
{
    function callback(objstr)
    {
        var objstr=JSON.parse(objstr);
        if(obj!=null && obj.ConstClsList.length>0)
        {
            var eleids=selectids.split(",");
            for(j=0;j<obj.ConstClsList.length;j++)
            {
                var ele=$("#"+eleids[j]);
                for(i=0;i<obj.ConstClsList[j].ConstList.length;i++)
                {
                    var dm=obj.ConstClsList[j].ConstList[i].Key;
                    var mc=obj.ConstClsList[j].ConstList[i].Value;
                    var strhtml="<option value='"+dm+"'>"+dm+";"+mc+"</option>";
                    ele.append(strhtml);
                }
            }
        }
    }
    connectajax(DBCenterServiceUrl+"/Core.asmx/GetMetaConstList",callback,"{'types':'"+consttypes+"'}");
}

function connectajax(url,callback,data,async,failcallback)
{
    var as=true;if(async==false)as=false;
    var strdata=data==null?"{}":data;
    $.ajax({async:as,url:url,type: "POST",dataType: "json",data: strdata,contentType: "application/json; charset=utf-8",
        success: function (json) { if (callback != null) { callback(json.d); } }, error: function (x, e) { if (failcallback != null) { failcallback(); } else { alertex(x.statusText, true); } } 
    });		
}

/*
   Function: ShowMetaTree
   
   描述：显示选择矿种或者行政区的控件
   
   参数:
   
      type - 树的类型，有两种：XZQ和KZ
        
      okCallBack - 选择成功后的回调函数，例如
        function okCallBack(dm,mc)
        {
            alertex("代码:"+dm+";名称:"+mc);
        }
      
   返回值:
   
       无
*/
function ShowMetaTree(type,okCallBack)
{
    var url=type=="XZQ"?"/Core.asmx/GetXZQList":"/Core.asmx/GetKZList";
    var title=type=="XZQ"?"选择行政区":"选择矿种";
    var data=type=="XZQ"? '{"condition":"1=1"}':'{}';
    var objtree=null;
    var overflowstatus=$("body").css("overflow-y");
    var strhtml='<div id="id_select_kz_dialog" style="cursor:default" title="'+title+'"><ul id="id_select_kz_navigation" class="ztree" style="width:100%;height: 300px"></ul></div>';
    connectajax(DBCenterServiceUrl+url,callback,data);
    $("body").append(strhtml);
    $("#id_select_kz_dialog" ).dialog({autoOpen: false,close:funCancel,width:280,buttons:{"确定": funOK,"取消":function(){$("#id_select_kz_dialog" ).dialog("close" );}}});
    var setting = {data: {simpleData: {enable: true}},callback: {onDblClick: funOK}};
    function callback(json) 
    {
        objtree=$.fn.zTree.init($("#id_select_kz_navigation"), setting, JSON.parse(json));
        $("html").css({"overflow-y":"scroll","height":"100%"});
        $("body").css({"height":"100%","overflow-y":"hidden"});
        $("body").append('<div id="id_select_kz_masklayer" style="filter:alpha(opacity=20);position:absolute;width:100%;height:100%;z-index:99;opacity:0.2;left:0;top:0;display:block;background:rgb(15, 30, 59)"></div>');
        diaobj=$("#id_select_kz_dialog" ).dialog("open");
        $("#id_select_kz_dialog" ).css("height","315px");
        if(type=="XZQ")
        {
            objtree.expandAll(true);
        }
    }
    function funOK() 
    {
        var selnodes=objtree.getSelectedNodes();
        if(selnodes!=null && selnodes.length>0)
        { 
            if(okCallBack!=null)
            {
                okCallBack(selnodes[0].id,selnodes[0].name);
                $("#id_select_kz_dialog" ).dialog("close" );
            } 
        }
    }
    function funCancel() 
    {
        $("#id_select_kz_dialog").remove();
        $("#id_select_kz_masklayer").remove();
        $("body").css("overflow-y",overflowstatus);
    }
}

//根据矿种不同，初始化不同的储量单位以及储量规模单位
function InitCLDW(txtKZDM,selGMCW,selCLDW){
    var m_clgmcb = new SmDataTable("META");
	  var m_kcdmcb=new SmDataTable("META");
	  var m_kzdm=$("#"+txtKZDM).val();
	  m_clgmcb.Init("select * from meta_clgm where kcdm=\\\'"+m_kzdm+"\\\'");
	  m_kcdmcb.Init("select * from meta_kcdm where kcdm=\\\'"+m_kzdm+"\\\'");
	  var straddclgmdw="";
	  var straddcldw="";
	  if(m_clgmcb.Data.Rows.length>0 && m_kcdmcb.Data.Rows.length>0)
	  {
		  for(var i=0;i<m_clgmcb.Data.Rows.length;i++)
		  {	     
			 straddcldw+="<option value='"+m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLGMID")]+"' dw='"+m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")]+"' sm='"+m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("SM")]+"'>"+m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")]+" "+m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("SM")]+"</option>";	    
		  }
		  straddclgmdw+="<option value='"+m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("KCDMID")]+"' dw='"+m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM")]+"'>"+m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM")]+"</option>";
		  if(m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")]!=null && m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")]!=""){
		    straddclgmdw+="<option value='"+m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("KCDMID")]+"' dw='"+m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")]+"'>"+m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")]+"</option>";
		  };
	  }
	  $("#"+selGMCW).html(straddclgmdw);
	  $("#"+selCLDW).html(straddcldw);

}
function InitCLDW2(txtKZDM,  selCLDW,strGMDW) {
    var m_clgmcb = new SmDataTable("META");
    var m_kcdmcb = new SmDataTable("META");
    var m_kzdm = $("#" + txtKZDM).val();
    m_clgmcb.Init("select * from meta_clgm where kcdm=\\\'" + m_kzdm + "\\\'");
    m_kcdmcb.Init("select * from meta_kcdm where kcdm=\\\'" + m_kzdm + "\\\'");
    var straddclgmdw = "";
    var straddcldw = "";
    var bContain = false;
    //去掉单位后面的 /年
    if (strGMDW.indexOf('/') > 0) {
        strGMDW = strGMDW.substring(0, strGMDW.indexOf('/'));
    }
    if (m_clgmcb.Data.Rows.length > 0 && m_kcdmcb.Data.Rows.length > 0) {
        for (var i = 0; i < m_clgmcb.Data.Rows.length; i++) {
            if (m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")] == strGMDW) {
                bContain = true;
                straddcldw += "<option selected='selected' value='" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLGMCBID")] + "' dw='" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")] + "' sm='" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("SM")] + "'>" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")] + " " + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("SM")] + "</option>";
            }
            else {
                straddcldw += "<option value='" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLGMCBID")] + "' dw='" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")] + "' sm='" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("SM")] + "'>" + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("CLDW")] + " " + m_clgmcb.Data.Rows[i][m_clgmcb.GetKeyIndex("SM")] + "</option>";
            }
        }
        
//        straddclgmdw += "<option value='" + m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("KCDMID")] + "' dw='" + m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM")] + "'>" + m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM")] + "</option>";
//        if (m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")] != null && m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")] != "") {
//            straddclgmdw += "<option value='" + m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("KCDMID")] + "' dw='" + m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")] + "'>" + m_kcdmcb.Data.Rows[0][m_kcdmcb.GetKeyIndex("SJGM2")] + "</option>";
//        };
    }
    if (bContain == false && strGMDW != "") {
        straddcldw += "<option selected='selected'  dw='" + strGMDW + "' >" + strGMDW + "</option>";
    }
   // $("#" + selGMCW).html(straddclgmdw);
    $("#" + selCLDW).html(straddcldw);
}
//手动触发文本框的change事件
function FireChangeEvent(txtID){
	if (document.getElementById(txtID).dispatchEvent){
	  var event = document.createEvent("HTMLEvents");
	  event.initEvent("change",true,false);
	  document.getElementById(txtID).dispatchEvent(event);
	}
	else{ 	        
		document.getElementById(txtID).fireEvent('onchange')
	}
};
//根据总储量值、储量单位、矿种不同，计算不同的总储量规模
function InitCLGM(txtCLGM,txtKZDM,txtZCL,selCLGMDW){
  var clgmcbid=$("#"+selCLGMDW+" option:selected").attr("value")==undefined?"":$("#"+selCLGMDW+" option:selected").attr("value");
  var kzdm=$("#"+txtKZDM).val();
  var zcl=$("#"+txtZCL).val();
  var m_clgmcb=new SmObjectData("KZJGK","CKS_CLGMCB");
  var m_sst=0;
  var m_ssx=0;
  var m_zcl=parseFloat(zcl);
  m_clgmcb.GetFirstSmObject("kcdm=\\\'"+kzdm+"\\\' and clgmcbid=\\\'"+clgmcbid+"\\\'");
  m_sst=parseFloat(m_clgmcb.GetValue("SST"));
  m_ssx=parseFloat(m_clgmcb.GetValue("SSX"));
  if(m_zcl<m_ssx)
  {
    $("#"+txtCLGM).val("小型");
  }
  else if(m_zcl>m_sst){
    $("#"+txtCLGM).val("大型");
  }
  else{
    $("#"+txtCLGM).val("中型");
  }
};
//根据矿种代码初始化矿种名称
function GetKZMCbyKZDM(KZDM){
  var m_kzmc="";
  var m_kzdm=new SmObjectData("META","META_KCDM");
  m_kzdm.GetFirstSmObject("kcdm=\\\'"+KZDM+"\\\'");
  m_kzmc=m_kzdm.GetValue("KCMC");
  return m_kzmc;
};
//根据行政区代码初始化行政区名称
function GetXZQMCbyXZQDM(XZQDM) {
    var m_kzmc = "";
    var m_kzdm = new SmObjectData("META", "META_XZQ");
    m_kzdm.GetFirstSmObject("XZQDM=\\\'" + XZQDM + "\\\'");
    m_kzmc = m_kzdm.GetValue("XZQMC");
    return m_kzmc;
};
//根据经济类型代码初始化经济类型名称
function GetJJLXMCbyJJLXDM(JJLX) {
    var jjlxclass = new SmObjectData("META", "META_CONSTCLS");
    jjlxclass.GetFirstSmObject("CONSTCLSTYPE=\\\'KCK_JJLX\\\'");
    var id = jjlxclass.GetValue("CONSTSLSID");
  var m_jjlxmc="";
  var m_jjlx = new SmObjectData("META", "META_CONST");
  m_jjlx.GetFirstSmObject("CONSTSLSID="+id+" and CONSTVALUE=\\\'"+JJLX+"\\\'");
  m_jjlxmc=m_jjlx.GetValue("CONSTTRANS");
  return m_jjlxmc;
};
//选完起始和终止日期后，算出间隔时间，以年为单位
function changeSpan( qsrqID,zzrqID,spanID) {
    var qsrq = $("#" + qsrqID).val();
    var zzrq = $("#" + zzrqID).val();
    if (qsrq && zzrq) {
        var s1 = qsrq.split('-');
        var s2 = zzrq.split('-');
        if (s1 && s2) {
            var year1 = s1[0];
            var month1 = s1[1];
            var year2 = s2[0];
            var month2 = s2[1];
            var year = parseInt(year2) - parseInt(year1);
            var month = parseFloat(month2) - parseFloat(month1);
            var rst = year.toString();
            if (month > 0) {
                rst += "." + month.toString();
            }
            else if (month < 0) {
               rst = (year - 1).toString() +"."+ (12+month).toString();
            }
            $("#" + spanID).val(rst);
        }
    }
}